import Vue from 'vue'

//转换目标成number 判断目标是否是合法数字
const isEffective = function (target){
  const effectiveField = parseInt(target)
  return effectiveField === effectiveField
}

export default {
  //id和路由命名时相同
  props: ['id'],
  //观察props: ['id']
  watch: {
    'id': function (newValue, oldValue) {
      if(isEffective(newValue)) {
        this.idEffectiveToDo(newValue, oldValue)//更新之后
        return
      }
      Vue.prototype.$Notice.error({
        title: '操作错误',
        desc: 'URL需要是合理值',
        duration: 3000
      })
      this.idNoneffectiveToDo(newValue, oldValue)
    }
  },
  methods: {
    //id有效要做的事 start
    idEffectiveToDo(newValue, oldValue) {

    },
    //id有效要做的事 end

    //id无效要做的事 start
    idNoneffectiveToDo(newValue, oldValue) {

    }
    //id无效要做的事 end
  },
  isEffective
}